package day10.client;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatClient {
    public static void main(String[] args) {
        Socket s=null;
        try {
             s=new Socket("192.168.100.86",9999);
            System.out.println(s+"连接了聊天服务器：");
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            PrintWriter pw=new PrintWriter(out,true);//true表示自动刷新
            Scanner input=new Scanner(System.in);
            while (true){
                System.out.println("唠嗑：");
                String msg=input.next();
                pw.println(msg);
                //pw.flush();
                String get=br.readLine();
                System.out.println("服务器回答："+get);
                if("byebye".equals(msg))
                    break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                s.close();
            } catch (Exception e) {

            }
        }

    }
}
